//    entity language compiler Copyright (C) 2011 Vincent Belliard

//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation version 3 of the License.

//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.

//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <typeinfo>
#include "types.h"
#include "entity.h"
#include "method.h"
#include "type.h"
#include "expression.h"
#include "global.h"
#include "object_class.h"
#include "scope.h"

// }{--------------------------------------------------------------

int T_block_scope::search_identifier(T_expression_identifier *expression, const T_string &name)
{
T_scope_local *local = locals.first ;
while (local != NULL)
	{
	if (strcmp(local->local->name.string(), name.string()) == 0)
		{
		expression->local = local->local ;
		expression->type = local->local->type_value ;
		return TRUE ;
		}
	local = local->next ;
	}
return FALSE ;
}

// }{--------------------------------------------------------------

int T_object_class_method_scope::search_identifier(T_expression_identifier *expression, const T_string &name)
{
T_prototype_argument *argument = method->type->prototype.arguments.first ;
while (argument != NULL)
	{
	if (strcmp(argument->name.string(), name.string()) == 0)
		{
		expression->argument = argument ;
		expression->type = argument->type ;
		return TRUE ;
		}
	argument = argument->next ;
	}
return method->object_class->search_identifier(expression, name) ;
}

// }{--------------------------------------------------------------

int T_object_class_constructor_scope::search_identifier(T_expression_identifier *expression, const T_string &name)
{
T_prototype_argument *argument = constructor->prototype.arguments.first ;
while (argument != NULL)
	{
	if (strcmp(argument->name.string(), name.string()) == 0)
		{
		expression->argument = argument ;
		expression->type = argument->type ;
		return TRUE ;
		}
	argument = argument->next ;
	}
return constructor->object_class->search_identifier(expression, name) ;
}

// }{--------------------------------------------------------------
